package com.jianyitech.asr.service;


import com.jianyitech.asr.conf.ConfigureProperties;
import com.jianyitech.asr.dtos.ConfigureDto;
import com.jianyitech.asr.dtos.Tenant;
import com.jianyitech.asr.dtos.TenantProduct;
import com.jianyitech.asr.exception.BizException;
import com.jianyitech.asr.mapper.AsrRuleMapper;
import com.jianyitech.asr.mapper.TenantMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class LoadConfigureService {


    private static final Logger logger = LoggerFactory.getLogger(LoadConfigureService.class);
    @Autowired
    private ConfigureProperties configureProperties;
    @Autowired
    TenantMapper tenantMapper;
    @Autowired
    AsrRuleMapper asrRuleMapper;
    /**
     * 获取ip和配置信息
     */
    public ConfigureDto loadConfigure(String id) {
        Tenant tenant=tenantMapper.findTenant(id);
        if (tenant!=null){
            ConfigureDto data = new ConfigureDto();
            data.setAccessKeyId(configureProperties.getAccessKeyId());
            data.setAccessKeySecret(configureProperties.getAccessKeySecret());
            data.setAppKey(configureProperties.getAppKey());
            data.setBalance(tenant.getBalance());
            data.setOverdraft(tenant.getOverdraft());
            TenantProduct tenantProduct=tenantMapper.findTenantProduct(id,"1003");
            if (tenantProduct!=null){
                data.setTenantProduct(tenantProduct);
            }
            data.setRuleList(asrRuleMapper.queryByTenantId(id));
            return data;
        }else {
            throw new BizException("租户未开通");
        }
    }
}
